package cn.tedu.sp03.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.type.TypeReference;

import cn.tedu.pojo.User;
import cn.tedu.service.UserService;
import cn.tedu.web.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
	
	@Value("${sp.user-service.users}")
	private String userJson;
	@Override
	public User getUser(Integer userId) {
		
		List<User> userList = JsonUtil.from(userJson, new TypeReference<List<User>>() {});
		for(User user:userList) {
			if(userId.equals(user.getId()))
				return user;
		}
		
		return new User(userId,"username:"+userId,"pwd:"+userId);
	}

	@Override
	public void addScore(Integer userId, Integer score) {
		log.info("为用户:"+userId+",增加了积分:"+score);
	}

}
